import { NInputNumber } from 'naive-ui'

const getShopHeader = (item) => {
  if (!item) {
    return []
  }

  const result = []

  Object.entries(item.skus).forEach(([k, v]) => {
    result.push({
      title: v.name,
      render: (row) => {
        return <span>{row.skus[k].value}</span>
      },
    })
  })

  return result
}

export const multipeConfig = (data = []) => {
  // 生成商品表头
  const headers = getShopHeader(data[0])

  return [
    {
      title: '商品规格',
      key: 'skus',
      children: headers,
    },
    {
      title: '销售价',
      key: 'pprice',
      render: (row) => {
        return <NInputNumber model-value={row.pprice} clearable placeholder="0" size="tiny" />
      },
    },
    {
      title: '市场价',
      key: 'oprice',
      render: (row) => {
        return <NInputNumber model-value={row.oprice} clearable placeholder="0" size="tiny" />
      },
    },
    {
      title: '成本价  ',
      key: 'cprice',
      render: (row) => {
        return <NInputNumber model-value={row.cprice} clearable placeholder="0" size="tiny" />
      },
    },
    {
      title: '库存',
      key: 'stock',
      render: (row) => {
        return <NInputNumber model-value={row.stock} clearable placeholder="0" size="tiny" />
      },
    },
    {
      title: '体积',
      key: 'volume',
      render: (row) => {
        return <NInputNumber model-value={row.volume} clearable placeholder="0" size="tiny" />
      },
    },
    {
      title: '重量',
      key: 'weight',
      render: (row) => {
        return <NInputNumber model-value={row.weight} clearable placeholder="0" size="tiny" />
      },
    },
    {
      title: '编码',
      key: 'code',
      render: (row) => {
        return <NInputNumber model-value={row.code} clearable placeholder="0" size="tiny" />
      },
    },
  ]
}
